package com.whut.transportation.adapter;

import java.util.List;

import com.whut.transportation.R;
import com.whut.transportation.entity.TransInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 运输数据绑定适配器
 */
public class SearchTransinfoAdapter extends BaseAdapter {
	private List<TransInfo> traninfos;// 要绑定的数据
	private LayoutInflater inflater;// 布局填充器
	private Context mContext;
	
	public SearchTransinfoAdapter(Context context,List<TransInfo> transInfos){
		this.mContext = context;
		this.traninfos = transInfos;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return traninfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return traninfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null; // 自定义结构体
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.activity_search_transinfo_item, null);
			holder = new ViewHolder();
			holder.transinfo_number = (TextView) convertView.findViewById(R.id.transinfo_number);
			holder.transinfo_trainNumber = (TextView) convertView.findViewById(R.id.transinfo_trainNumber);
			holder.transinfo_train = (TextView) convertView.findViewById(R.id.transinfo_train);
			holder.transinfo_station = (TextView) convertView.findViewById(R.id.transinfo_station);
			holder.transinfo_time = (TextView) convertView.findViewById(R.id.transinfo_time);
			holder.transinfo_goods = (TextView) convertView.findViewById(R.id.transinfo_goods);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		TransInfo transInfo = traninfos.get(position);
		holder.transinfo_number.setText(transInfo.getNumber());
		holder.transinfo_trainNumber.setText(transInfo.getTrainNumber());
		holder.transinfo_train.setText(transInfo.getTrain());
		holder.transinfo_station.setText(transInfo.getStation());
		holder.transinfo_goods.setText(transInfo.getGoods());
		holder.transinfo_time.setText(transInfo.getTime());
		return convertView;
	}
	
	

}
